import JQuery from 'jquery';
import util from '@/js/util/util.js';

let treeAttr = {
    setAttribute: function(element) {
        if (element.component === 'Tree') {
            this.setCheck(this.getTreeMultipleValueName(), element.attribute.treeHasCheckBox);
            this.setCheck(this.getTreeLinkValueName(), element.attribute.treeCheckStrictly);
        }
    },
    setValue: function(id, value) {
        let obj = JQuery('#' + id);
        obj.val(value);
    },
    setCheck: function(id, value) {
        let obj = JQuery('#' + id);
        obj.prop('checked', value);
    },
    getTreeMultipleValueName: function() {
        return window.getRootName() + 'ATTRIBUTE_TREEHASCHECKBOX';
    },
    getTreeLinkValueName: function() {
        return window.getRootName() + 'ATTRIBUTE_TREECHECKSTRICTLY';
    },
    setTreeMultiple(element, value, updateInput = true) {
        element.attribute.treeHasCheckBox = value;
        updateInput && this.setValue(this.getTreeMultipleValueName(), value);
    },
    setTreeLink(element, value, updateInput = true) {
        element.attribute.treeCheckStrictly = value;
        updateInput && this.setValue(this.getTreeLinkValueName(), value);
    },
    setActiveColor: function(element, value) {
        element.attribute.menuActiveColor = util.isBlank(value) ? '#FFFFFFFF' : util.rgbaToHexColor(value);
    }
};

export default treeAttr;